<?php

class RegisterView {

	private $r_username = "username";
	private $r_password = "password";
	private $d_username = "d_username";
	private $d_password = "d_password";
	private $remember = "remember";
	private $delete = "delete";
	private $register = "register";
	
	//konstanter som kan anropas i RegisterController
	const REGISTRED = 0;
	const EXISTS = 1;
	const VALIDATIONFAIL = 2;
	const REGISTRATIONFAIL = 3;
	const DELETE = 4;
	const DOESNOTEXIST = 5;	
	
	// Genom POST kan man anropa formuläret i andra funktioner
	public function DoRegisterBox() {
		$RegisterForm = "
		<form method='POST'>
  		Username: <input type='text' name='" . $this -> r_username . "' size='15' /><br />
  		Password: <input type='password' name='" . $this -> r_password . "'  size='15' /><br />
  		<input type='hidden' value='active' name='" . $this -> register . "'/>
  		<p><input type='submit' value='Register'/></p>
  		
  		</form>";
		return $RegisterForm;
	}
	
	
	//switch-sats för felhanteringsmeddelanden
	public static function statusMessage($n){
				$statusMessage = null;
				
				switch($n){
					case self:: REGISTRED:
						$statusMessage .= "Användaren registrerades.";
						break;
					case self:: EXISTS:
						$statusMessage .= "Användare existerar redan";
						break;
					case self:: VALIDATIONFAIL:
						$statusMessage .= "Validering av användarnamn/lösenord misslyckades. Minst 6 tecken, högst 12.";
						break;
					case self:: REGISTRATIONFAIL:
						$statusMessage .= "Användaren kunde inte registreras.";
						break;
					case self:: DELETE:
						$statusMessage .= "Användaren togs bort.";
						break;
					case self:: DOESNOTEXIST:
						$statusMessage .= "Användaren existerar inte.";
						break;
					}
		return "<p class='statusMessage'> $statusMessage</p>";
	}
			
	//Ta bort-knapp
	public function DoDeleteBox() {
		$deleteButton = "<form method='POST'>
		Username: <input type='text' name='" . $this -> d_username . "' size='15' /><br />
  		Password: <input type='password' name='" . $this -> d_password . "'  size='15' /><br />
		<input type='hidden' value='active' name='" . $this -> delete . "'/>
		<input type='submit' value='Delete'/></form>";
		return $deleteButton;
	}
	
	public function GetUserName() {
		if (isset($_POST[$this -> r_username]) == true) {
			//return the variable
			return $_POST[$this -> r_username];
		} 
		return NULL;
	}
	
	public function d_GetUserName() {
		if (isset($_POST[$this -> d_username]) == true) {
			//return the variable
			return $_POST[$this -> d_username];
		} 
		return NULL;
	}
	
	public function d_GetPassword() {
		if (isset($_POST[$this -> d_password]) == true) {
			//return the variable
			return $_POST[$this -> d_password];
		} 
		return NULL;
	}

	public function GetPassword() {
		if (isset($_POST[$this -> r_password]) == true) {
			//return the variable
			return $_POST[$this -> r_password];
		} 
		return NULL;
	}

	// Så länge värdena som mottas inte är null så får man inte felmedellande
	public function TriedToRegister() {
		if ((isset($_POST[$this -> register]) == true) && ($this -> GetUserName() != NULL) && ($this -> GetPassword() != NULL)) {
			return true;
		} else {
			return false;
		}
	}
	// anropar elementen för knappen och via isset kollar man om den trycks på
	public function TriedToDelete() {
		if ((isset($_POST[$this -> delete]) == true)){
			return true;
		} else {
			return false;
		}
	}

}
?>
